const http = require('http')
const fs = require('fs')

const port = 3000
const hostname = '127.0.0.1'

const server = http.createServer((req, res) => {
  res.setHeader('Content-Type', 'application/json;charset=utf-8')
  const pathName = req.url.substring(1)
  fs.readFile(pathName, (err, data) => {
    if (err) {
      res.statusCode = 404
    } else {
      res.statusCode = 200
      res.write(data)
    }
    res.end()
  })
})

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}...`)
})
